﻿package util.select {
	import flash.display.Sprite;
	
	public class SelectList extends Sprite {
		private var labels:Array;
		private var values:Array;
		
		private var editor:Editor;
		private var maxWidth:int;
		private var align:String;
		private var type:String;
		
		public function SelectList(editor:Editor, align:String, type:String):void {
			this.editor = editor;
			this.align = align;
			this.type = type;
			visible = false;
			labels = new Array();
			values = new Array();
			maxWidth = 0;
		}
		
		public function addItem(label:String, value:String):void {
			labels.push(label);
			values.push(value);
		}
		
		public function create():void {
			for (var i:int = 0; i < labels.length; i++) {
				var item:SelectItem = new SelectItem(labels[i], values[i], align, type, editor);
				//设置最大宽度
				if (item.width > maxWidth) {
					maxWidth = item.width;
				}
				item.y = height;
				addChild(item);
			}
			for (var j:int = 0; j < numChildren; j++) {
				var child:SelectItem = getChildAt(j) as SelectItem;
				child.setWidth(maxWidth);
			}
		}
		
		public function show(x:int, y:int):void {
			this.x = x;
			this.y = y;
			visible = true;
		}
	}
}